﻿using Quartz;
using Quartz.Impl;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PoXiao
{
    internal class CheckIsOk : IJob
    {
        public Task Execute(IJobExecutionContext context)
        {
            return Task.Run(() =>
            {
                try
                {
                    //每周五晚上10点运行Form1.test这个方法
                    Form1.IsOkJob();
                }
                catch (Exception ex)
                {

                }
            });
        }

        public class Quartz
        {
            public static async Task Start()
            {
                try
                {
                    // Grab the Scheduler instance from the Factory
                    NameValueCollection props = new NameValueCollection
                {
                    { "quartz.serializer.type", "binary" }
                };
                    StdSchedulerFactory factory = new StdSchedulerFactory(props);
                    IScheduler scheduler = await factory.GetScheduler();
                    await scheduler.Start();
                    IJobDetail tfAlarmJob = JobBuilder.Create<CheckIsOk>()
                        .WithIdentity("tfAlarmJob", "group1")
                        .Build();
                    ITrigger trigger = TriggerBuilder.Create()
                        .WithIdentity("trigger", "group1")
                     .WithCronSchedule("* 0/15 * * * ?")//每15分钟执行一次
                         .Build();
                    await scheduler.ScheduleJob(tfAlarmJob, trigger);
                }
                catch (Exception ex)
                {

                }
            }
            public interface IJob
            {
            }
        }

    }
}
